//
//  User.m
//  百车易车险
//
//  Created bychenxu on 14-7-30.
//  Copyright (c) 2014年 chenxu. All rights reserved.
//

#import "User.h"
#import "BPush.h"
@implementation User


//- (instancetype)init
//{
//    self = [super init];
//    if (self) {
//        _Uid = @"";
//        _Username = @"";
//        _Email = @"";
//        _Address = @"";
//        _Flag = @"";
//        _Nickname = @"";
//        _Phone = @"";
//        _Phoneflag = @"";
//        _Question = @"";
//        _Answer = @"";
//        _Password = @"";
//        _resetPassword = @"";
//        _resetPasswordConfirm = @"";
//        _introduction = @"";
//        _Bid = @"";
//        _Shouhuoren =@"";
//        _Shouyiid = @"";
//        _Shouyiname = @"";
//        _Channel_id = kChannel_id;
//        _User_id = kUser_id;
//        _Chezhuid = @"";
//        _Chezhuname = @"";
//    }
//    return self;
//}


- (NSDictionary *)toResetPasswordParams{
    return @{@"username" : self.Username ,
             @"password" : self.Password ,
             @"newpassword" : self.resetPassword };
}

//- (NSString *)slogan{
//    if (_slogan && _slogan.length > 0) {
//        return _slogan;
//    }else{
//        return @"座右铭未填写";
//    }
//}


/*!
 *  @brief  更新用户信息
 *  @return 用户信息dict
 */
- (NSDictionary *)toUpdateInfoParams{
    return @{
             @"username" : _Username,
             @"email" : _Email,
             @"address" : _Address,
             @"phone" : _Phone,
             @"shouhuoren" :_Shouhuoren,
             @"nickname" :_Nickname
             };
}


- (NSString *)changePasswordTips{
    NSString *tipStr = nil;
    if (!self.Password || self.Password.length <= 0){
        tipStr = @"请输入当前密码";
    }else if (!self.resetPassword || self.resetPassword.length <= 0){
        tipStr = @"请输入新密码";
    }else if (!self.resetPasswordConfirm || self.resetPasswordConfirm.length <= 0) {
        tipStr = @"请确认新密码";
    }else if (![self.resetPassword isEqualToString:self.resetPasswordConfirm]){
        tipStr = @"两次输入的密码不一致";
    }else if (self.resetPassword.length < 6){
        tipStr = @"新密码不能少于6位";
    }else if (self.resetPassword.length > 64){
        tipStr = @"新密码不得长于64位";
    }
    return tipStr;
}

- (NSString *)registUserTips{
    NSString *tipStr = nil;
    
    if (!self.Username || self.Username.length <= 0){
        tipStr = @"请输入用户名";
    }
    else if (!self.Password || self.Password.length <= 0){
        tipStr = @"请输入密码";
    }
    else if (!self.registPass || self.registPass.length <= 0){
        tipStr = @"请确认密码";
    }
    else if (![self.Password isEqualToString:self.registPass]){
        tipStr = @"两次输入的密码不一致";
    }
    else if (self.Password.length < 6){
        tipStr = @"密码不能少于6位";
    }
    else if (self.Password.length > 64){
        tipStr = @"密码不得长于64位";
    }
    else if (!self.Answer || self.Answer.length <= 0 ){
        tipStr = @"请输入密保问题答案";
    }
    else if (!self.Question || self.Question.length <= 0 ){
        tipStr = @"请选择密保问题";
    }
 
    return tipStr;
}

- (NSDictionary *)tousernameParams{
    return @{@"username":self.Username};
}
- (NSDictionary *)toUsernameParams{
    return @{@"Username":self.Username};
}

- (NSDictionary *)toRegistParams{
    return @{@"username" : self.Username,
             @"password" : self.Password,
             @"Question" : self.Question,
             @"Answer" : self.Answer,
             @"User_id": [BPush getUserId],
             @"Channel_id": [BPush getChannelId]
             };
}

- (NSDictionary *)toSaveUserParams{
    return @{@"Username" : self.Username,
             @"Password" : self.Password,
             @"Question" : self.Question,
             @"Answer" : self.Answer
             };
}


- (bool)isSameUser:(User*)user{
    return _Uid == user.Uid;
}

- (NSString*)getIconUrl{
    return  [NSString stringWithFormat:@"%@%@.jpg",kNetPath_ImgBase,_Username];
}

#pragma mark 归档代理
- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:_Uid forKey:@"uid"];
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    _Uid = [aDecoder decodeObjectForKey:@"uid"];
  
    
    return self;
}
@end
